<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { searchAllVo } from '@/api/flow.js';

const route = useRoute();
const router = useRouter();
const transactionsId = route.params.transactionsId;
const flowDetail = ref<any>(null);

onMounted(async () => {
  await searchAll();
});

async function searchAll() {
  try {
    const res = await searchAllVo(transactionsId);
    flowDetail.value = res.data.data;
    console.log("flowDetail", flowDetail.value);
  } catch (e) {
    console.error("获取流水详情失败:", e);
  }
}

function goToOrders() {
  router.push("/myOrder");
}
</script>

<template>
  <div class="flow-page">
    <h2 class="title">流水详情</h2>

    <div v-if="flowDetail" class="flow-card">
      <div class="row">
        <span class="label">流水号：</span>
        <span class="value">{{ flowDetail.transactionsNo }}</span>
      </div>

      <div class="row">
        <span class="label">创建时间：</span>
        <span class="value">{{ flowDetail.transactionCreatedAt }}</span>
      </div>

      <div class="row">
        <span class="label">支付金额：</span>
        <span class="value price">￥{{ flowDetail.amount }}</span>
      </div>

      <div class="row">
        <span class="label">订单号：</span>
        <span class="value">{{ flowDetail.orderNumber }}</span>
      </div>

      <div class="row">
        <span class="label">下单时间：</span>
        <span class="value">{{ flowDetail.orderCreatedAt }}</span>
      </div>
    </div>

    <div v-else class="loading">
      正在加载中...
    </div>

    <div class="btn-wrapper">
      <button class="order-btn" @click="goToOrders">查看我的所有订单</button>
    </div>
  </div>
</template>

<style scoped>
.flow-page {
  max-width: 800px;
  margin: 30px auto;
  padding: 20px 30px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  font-family: "Microsoft YaHei", sans-serif;
}

.title {
  font-size: 22px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  text-align: center;
}

.flow-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
}

.label {
  font-weight: bold;
  color: #666;
  min-width: 100px;
  text-align: right;
}

.value {
  color: #333;
  flex: 1;
}

.price {
  color: #ff6600;
  font-size: 16px;
  font-weight: bold;
}

.btn-wrapper {
  text-align: center;
  margin-top: 30px;
}

.order-btn {
  padding: 10px 20px;
  background: #409eff;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 15px;
  cursor: pointer;
  transition: 0.3s;
}
.order-btn:hover {
  background: #66b1ff;
}

.loading {
  text-align: center;
  color: #888;
  margin: 40px 0;
}
</style>
